import React from 'react';
import {DefaultOptionType} from "rc-select/lib/Select";
import {Form, Select} from "antd";
import useAsyncEffect from "hooks/useAsyncEffect";
import LogFactory from "log/LogFactory";

import {OdoTypeSelectProps} from "../../../init";
import {OutboundDeliveryOrder} from "type/OutboundDeliveryOrder";
import DrpSettingHandler from "../../../DrpSettingHandler";
import {getClientOptions} from "../../../SeleteOptionHanlder";

const log = LogFactory.getLog("OdoTypeSelect");
const SaleOdoSelect = ({form}: OdoTypeSelectProps) => {
    const [loading,setLoading] = React.useState<boolean>(true) ;
    const [options,setOptions] = React.useState<DefaultOptionType[]>([]) ;
    log.info("销售出库组件加载") ;
    useAsyncEffect(async () => {
        setOptions( await getClientOptions()) ;
        form.setFieldValue("odoFlow",DrpSettingHandler.getInstance().getConfig().defaultClient) ;
        setLoading(false) ;
    }) ;
    return ( <Form.Item<OutboundDeliveryOrder> label={"销售单位(个人)"} name={"odoFlow"} required>
            <Select loading={loading} options={options}/>
        </Form.Item>
    );
};

export default SaleOdoSelect;